package com.jaywalkable.vkeyboard.util;

import java.util.Comparator;

public class StringLengthComparator implements Comparator<String> {

    /**
     * Compares the length first. If both are of same length then default <code>String</code> comparison is
     * returned.
     */
    public int compare(String o1, String o2) {
        int lenComp = Integer.valueOf(o1.length()).compareTo(Integer.valueOf(o2.length()));
        if (lenComp != 0) {
            return lenComp;
        }

        if (o1.equals(o2)) {
            return 0;
        }

        return o1.compareTo(o2) > 0 ? 1 : -1;
    }
}
